package cn.hdu.liang.ch3;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

@FunctionalInterface
interface BufferedReaderProcessor {
    String process(BufferedReader b) throws IOException;
}

public class ExecuteAround {
    private static String DATA_PATH = "src/cn/hdu/liang/ch3/data.txt";


    public static void main(String[] args) throws IOException {

        System.out.println(processFile());

        String result = processFile(br -> br.readLine() + br.readLine());
        System.out.println(result);
    }

    public static String processFile(BufferedReaderProcessor p) throws IOException {
        try(BufferedReader br = new BufferedReader(new FileReader(DATA_PATH))) {
            return p.process(br);
        }
    }

    public static String processFile() throws IOException {
        try(BufferedReader br = new BufferedReader(new FileReader(DATA_PATH))) {
            return br.readLine();
        }
    }
}
